﻿// -----------------------------------------------------------------------
// <copyright file="AmazonSigningEndpointBehavior.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems, 2012. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace MBOP.DistributedServices.AmazonHeaders
{
	#region Usings

	using System;
	using System.Configuration;
	using System.ServiceModel.Channels;
	using System.ServiceModel.Description;
	using System.ServiceModel.Dispatcher;

	#endregion

	/// <summary>
	/// The <see cref="IEndpointBehavior"/> implementer, which represent the endpoint behavior for amazon.
	/// </summary>
	public class AmazonSigningEndpointBehavior : IEndpointBehavior
	{
		#region Private Fields

		/// <summary>
		/// Represents the access key id.
		/// </summary>
		private string _accessKeyId = string.Empty;

		/// <summary>
		/// Represents the secret key.
		/// </summary>
		private string _secretKey = string.Empty;

		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="AmazonSigningEndpointBehavior"/> class.
		/// </summary>
		/// <param name="accessKeyId">The access key id</param>
		/// <param name="secretKey">The secret key</param>
		public AmazonSigningEndpointBehavior(string accessKeyId, string secretKey)
		{
			this._accessKeyId = accessKeyId;
			this._secretKey = secretKey;
		}

		#endregion

		#region IEndpointBehavior Implementation

		/// <summary>
		/// Implements a modification or extension of the client across an endpoint.
		/// </summary>
		/// <param name="serviceEndpoint">The endpoint that is to be customized.</param>
		/// <param name="clientRuntime">The client runtime to be customized.</param>
		public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
		{
			clientRuntime.MessageInspectors.Add(new AmazonSigningMessageInspector(this._accessKeyId, this._secretKey));
		}

		/// <summary>
		/// Implements a modification or extension of the service across an endpoint.
		/// </summary>
		/// <param name="serviceEndpoint">The endpoint that exposes the contract.</param>
		/// <param name="endpointDispatcher">The endpoint dispatcher to be modified or extended.</param>
		public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher) 
		{
			return; 
		}

		/// <summary>
		/// Implement to confirm that the endpoint meets some intended criteria.
		/// </summary>
		/// <param name="serviceEndpoint">The endpoint to validate.</param>
		public void Validate(ServiceEndpoint serviceEndpoint) 
		{ 
			return; 
		}

		/// <summary>
		/// Implement to pass data at runtime to bindings to support custom behavior.
		/// </summary>
		/// <param name="serviceEndpoint">The endpoint to modify.</param>
		/// <param name="bindingParameters">The objects that binding elements require to support the behavior.</param>
		public void AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParameters) 
		{ 
			return;
		}

		#endregion
	}
}
